/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Giaodien;

import Lop.lNEN;
import Lop.lNHOM_NEN;
import Lop.lDIACHINB;
import Lop.lDIENTICH;
import Lop.lKHU_TDC;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.SQLException;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
import javax.swing.table.DefaultTableModel;
import net.proteanit.sql.DbUtils;
import oracle.jdbc.OracleResultSet;

/**
 *
 * @author lhqbao
 */
public class gNen1 extends javax.swing.JInternalFrame {

    /**
     * Creates new form gNen1
     */
    private int flag=0;
    public gNen1() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbNEN = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtManen = new javax.swing.JTextField();
        txtTennen = new javax.swing.JTextField();
        cbCapphat = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtChieudai = new javax.swing.JTextField();
        txtChieurong = new javax.swing.JTextField();
        txtSonen = new javax.swing.JTextField();
        txtTenduong = new javax.swing.JTextField();
        cbNhomnen = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        btThem2 = new javax.swing.JButton();
        btSua2 = new javax.swing.JButton();
        btXoa2 = new javax.swing.JButton();
        btThoat2 = new javax.swing.JButton();
        btLuu2 = new javax.swing.JButton();
        btBoqua1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        tbNEN.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        tbNEN.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7", "Title 8", "Title 9"
            }
        ));
        tbNEN.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbNENMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbNEN);

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin Nền", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 13))); // NOI18N

        jLabel3.setText("Mã Nền");

        jLabel4.setText("Tên Nền");

        jLabel6.setText("Cấp phát");

        cbCapphat.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtManen)
                    .addComponent(txtTennen)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cbCapphat, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 136, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtManen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTennen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cbCapphat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin liên quan", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 13))); // NOI18N

        jLabel8.setText("Chiều dài");

        jLabel9.setText("Chiều rộng");

        jLabel10.setText("Số nền");

        jLabel11.setText("Tên đường");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtChieudai)
                    .addComponent(txtChieurong)
                    .addComponent(txtSonen)
                    .addComponent(txtTenduong))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtChieudai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtChieurong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtSonen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtTenduong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        cbNhomnen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbNhomnenActionPerformed(evt);
            }
        });

        jLabel5.setText("Nhóm Nền");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(cbNhomnen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbNhomnen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(13, 13, 13)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btThem2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btThem2.setText("Them ");
        btThem2.setName("btThem"); // NOI18N
        btThem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btThem2MouseClicked(evt);
            }
        });

        btSua2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btSua2.setText("Sua");
        btSua2.setName("btSua"); // NOI18N
        btSua2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btSua2MouseClicked(evt);
            }
        });

        btXoa2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btXoa2.setText("Xoa");
        btXoa2.setName("btXoa"); // NOI18N
        btXoa2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btXoa2MouseClicked(evt);
            }
        });

        btThoat2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btThoat2.setText("Thoat");
        btThoat2.setName("btThoat"); // NOI18N
        btThoat2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btThoat2MouseClicked(evt);
            }
        });
        btThoat2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThoat2ActionPerformed(evt);
            }
        });

        btLuu2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btLuu2.setText("Luu");
        btLuu2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btLuu2MouseClicked(evt);
            }
        });
        btLuu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLuu2ActionPerformed(evt);
            }
        });

        btBoqua1.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btBoqua1.setText("Bo qua");
        btBoqua1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btBoqua1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(btLuu2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(btBoqua1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(btThem2)
                        .addGap(6, 6, 6)
                        .addComponent(btSua2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btXoa2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(btThoat2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThem2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btSua2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btXoa2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btThoat2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btLuu2, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                    .addComponent(btBoqua1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 30)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 51, 255));
        jLabel1.setText("THÔNG TIN CHI TIẾT VỀ NỀN");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(152, 152, 152))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tbNENMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbNENMouseClicked
        // TODO add your handling code here:
        try{
            DefaultTableModel model = (DefaultTableModel) tbNEN.getModel();

            txtManen.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 0));
            txtTennen.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 1));

            txtChieudai.setText( model.getValueAt(tbNEN.getSelectedRow(), 2).toString());
            txtChieurong.setText( model.getValueAt(tbNEN.getSelectedRow(), 3).toString());
            txtSonen.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 4));
            txtTenduong.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 5));
            cbCapphat.setSelectedItem((String) model.getValueAt(tbNEN.getSelectedRow(), 6));
           
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }//GEN-LAST:event_tbNENMouseClicked
    
    public boolean kiemtra()
    {
        if(txtManen.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap ma nen");
            return false; 
        }
        if(txtTennen.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap ten nen");
            return false;
        }
        if(cbNhomnen.getSelectedItem().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon nhom nen");
            return false;
        }
        if(txtChieudai.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap chieu dai");
            return false;
        }
        if(txtChieurong.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap chieu rong");
            return false;
        }
        if(txtSonen.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap nen so");
            return false;
        }
         if(txtTenduong.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap ten duong");
            return false;
        }
       
        return true;
    }
    public void hienthiNEN()
    {
        flag=0;
        
        txtManen.setEnabled(false);
        txtTennen.setEnabled(false);
        txtChieudai.setEnabled(false);
        txtChieurong.setEnabled(false);
        txtSonen.setEnabled(false);
        txtTenduong.setEnabled(false);
               
        btThem2.setVisible(true);
        btSua2.setVisible(true);
        btXoa2.setVisible(true);
        btThoat2.setVisible(true);
             
        btLuu2.setVisible(false);
        btBoqua1.setVisible(false);
        
        lNEN nen = new lNEN((lNHOM_NEN)cbNhomnen.getSelectedItem());
        OracleResultSet rs = nen.hienthiNEN(fMain.cnn);
        tbNEN.setModel(DbUtils.resultSetToTableModel(rs));
       
    }
    
     private void setDataIntoCboNhomnen() throws SQLException{
        OracleResultSet rs = (new lNEN()).getDsNHOM_NEN(fMain.cnn);
        int rowCount = 0;
        if(rs.last()) rowCount = rs.getRow();
        
        if(rowCount > 0){
            rs.beforeFirst();
            lNHOM_NEN[] nhomnen = new lNHOM_NEN[rowCount];
            int i = 0;
            while(rs.next()){
                nhomnen[i] = new lNHOM_NEN();
                nhomnen[i].setManhom(rs.getString(1));
                nhomnen[i].setTennhom(rs.getString(2));
                
                i++;
            }
            this.cbNhomnen.setModel(new javax.swing.DefaultComboBoxModel(nhomnen));
            this.cbNhomnen.setRenderer(new ItemRenderer());
        }
    }
    
    class ItemRenderer extends BasicComboBoxRenderer  
    {  
        public Component getListCellRendererComponent(  
            JList list, Object value, int index,  
            boolean isSelected, boolean cellHasFocus)  
        {  
            super.getListCellRendererComponent(list, value, index,  
                isSelected, cellHasFocus);  
  
            if (value != null)  
            {  
                lNHOM_NEN item = (lNHOM_NEN)value;  
                setText( item.getTennhom().toUpperCase() );  
            }  
  
            if (index == -1)  
            {  
                lNHOM_NEN item = (lNHOM_NEN)value;  
                setText( "" + item.getTennhom());  
            }  
            return this;  
        }  
    }  
    
    
    private void btThem2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btThem2MouseClicked
        // TODO add your handling code here:
        hienthiNEN();
        flag=1;
        txtManen.setText(null);
        txtTennen.setText(null);
        txtChieudai.setText(null);
        txtChieurong.setText(null);
        txtSonen.setText(null);
        txtTenduong.setText(null);
       
        txtManen.setEnabled(true);
        txtTennen.setEnabled(true);
        txtChieudai.setEnabled(true);
        txtChieurong.setEnabled(true);
        txtSonen.setEnabled(true);
        txtTenduong.setEnabled(true);
        cbNhomnen.setEnabled(true);

        btThem2.setVisible(false);
        btSua2.setVisible(false);
        btXoa2.setVisible(false);
        btThoat2.setVisible(false);
        btLuu2.setVisible(true);
        btBoqua1.setVisible(true);
        txtManen.setEnabled(true);
    }//GEN-LAST:event_btThem2MouseClicked

    private void btSua2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btSua2MouseClicked
        // TODO add your handling code here:
        flag=2;
        txtManen.setEnabled(false);
        if(txtManen.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon nen de sua");
            return;
        }

        txtTennen.setEnabled(true);
        txtChieudai.setEnabled(true);
        txtChieurong.setEnabled(true);
        txtSonen.setEnabled(true);
        txtTenduong.setEnabled(true);
      
        btThem2.setVisible(false);
        btThoat2.setVisible(false);
        btSua2.setVisible(false);
        btXoa2.setVisible(false);

        btLuu2.setVisible(true);
        btBoqua1.setVisible(true);
    }//GEN-LAST:event_btSua2MouseClicked

    private void btXoa2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btXoa2MouseClicked
        // TODO add your handling code here:

        if(txtManen.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon khu de xoa");
            return;
        }

        int reply = JOptionPane.showConfirmDialog(null, "Ban co chac xoa khong ?", "Xac nhan xoa", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION)
        {
            lNEN nen = new lNEN();
            nen.setManen(txtManen.getText());
            nen.xoaNEN(fMain.cnn);
            JOptionPane.showMessageDialog(null, "Xoa thanh cong!");
            flag=0;
        }
        hienthiNEN();
    }//GEN-LAST:event_btXoa2MouseClicked

    private void btThoat2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btThoat2MouseClicked
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btThoat2MouseClicked

    private void btThoat2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThoat2ActionPerformed
        // TODO add your handling code here:
        /*
        dispose();
        new Sub_main_QLTDC().setVisible(true);
        */
    }//GEN-LAST:event_btThoat2ActionPerformed

    private void btLuu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btLuu2MouseClicked
        // TODO add your handling code here:

        if(!kiemtra()) return;
        try{
            if(flag==1)
            {
                lDIACHINB dcn = new lDIACHINB(txtSonen.getText(), txtTenduong.getText());
                lDIENTICH dt = new lDIENTICH(Float.parseFloat(txtChieudai.getText()), Float.parseFloat(txtChieurong.getText()));
                lNEN nen = new lNEN(txtManen.getText(),txtTennen.getText(),dt,dcn,cbCapphat.getSelectedItem().toString(),(lNHOM_NEN)cbNhomnen.getSelectedItem());
                nen.themNEN(fMain.cnn);
                JOptionPane.showMessageDialog(null, "Them thanh cong!");
                flag=0;
            }
            if(flag==2)
            {

                lDIACHINB dcn = new lDIACHINB(txtSonen.getText(), txtTenduong.getText());
                lDIENTICH dt = new lDIENTICH(Float.parseFloat(txtChieudai.getText()), Float.parseFloat(txtChieurong.getText()));
                lNEN nen = new lNEN(txtManen.getText(),txtTennen.getText(),dt,dcn,cbCapphat.getSelectedItem().toString(),(lNHOM_NEN)cbNhomnen.getSelectedItem());
                nen.suaNEN(fMain.cnn);
                JOptionPane.showMessageDialog(null, "Cap nhat thanh cong!");
                flag=0;
            }
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Cap nhat khong thanh cong");
        }
        hienthiNEN();
    }//GEN-LAST:event_btLuu2MouseClicked

    private void btLuu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLuu2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btLuu2ActionPerformed

    private void btBoqua1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btBoqua1MouseClicked
        // TODO add your handling code here:

        hienthiNEN();
        try{
            DefaultTableModel model = (DefaultTableModel) tbNEN.getModel();

            txtManen.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 0));
            txtTennen.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 1));
            txtChieudai.setText(model.getValueAt(tbNEN.getSelectedRow(), 2).toString());
            txtChieurong.setText(model.getValueAt(tbNEN.getSelectedRow(), 3).toString());
            txtSonen.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 4));
            txtTenduong.setText((String) model.getValueAt(tbNEN.getSelectedRow(), 5));
            cbCapphat.setSelectedItem((String) model.getValueAt(tbNEN.getSelectedRow(), 6));
           

        }catch(Exception e){}
    }//GEN-LAST:event_btBoqua1MouseClicked

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        
        try{
        setDataIntoCboNhomnen();
        if(this.cbNhomnen.getItemCount() > 0) this.cbNhomnen.setSelectedIndex(0);
        this.cbNhomnen.addItemListener(new ItemChangeListener());
        hienthiNEN();
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }//GEN-LAST:event_formInternalFrameOpened

    private void cbNhomnenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbNhomnenActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_cbNhomnenActionPerformed
    class ItemChangeListener implements ItemListener{
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                
                lNHOM_NEN nhomnen = (lNHOM_NEN)event.getItem();
                lNEN nen = new lNEN(nhomnen);
                OracleResultSet rs = nen.hienthiNEN(fMain.cnn);
                tbNEN.setModel(DbUtils.resultSetToTableModel(rs));
                
               
            }
        }       
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btBoqua1;
    private javax.swing.JButton btLuu2;
    private javax.swing.JButton btSua2;
    private javax.swing.JButton btThem2;
    private javax.swing.JButton btThoat2;
    private javax.swing.JButton btXoa2;
    private javax.swing.JComboBox cbCapphat;
    private javax.swing.JComboBox cbNhomnen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbNEN;
    private javax.swing.JTextField txtChieudai;
    private javax.swing.JTextField txtChieurong;
    private javax.swing.JTextField txtManen;
    private javax.swing.JTextField txtSonen;
    private javax.swing.JTextField txtTenduong;
    private javax.swing.JTextField txtTennen;
    // End of variables declaration//GEN-END:variables
}
